﻿using DBServer.Selenium.Extenium.Exception;
using DBServer.Selenium.Extenium.Path;
using Selenium;

namespace DBServer.Selenium.Extenium.Fixtures
{
    public class SplitButtonFixture : ExtComponentFixture
    {

        public SplitButtonFixture(ISelenium driver, IPath path)
            : base(driver, path)
        {
        }

        public void Click()
        {
            SafeExec(Path.Eval() + ".btnEl.dom.click();");
        }

        public MenuFixture ShowGetMenu()
        {
            SafeExec(Path.Eval() + ".showMenu()");
            var id = SafeExec(Path.Eval() + ".showMenu().menu.id;");
            return new MenuFixture(Driver, id);            
        }

        public void RequireEnabled()
        {
            var result = bool.Parse(SafeExec(Path.Eval() + ".disabled"));
            if (result)
            {
                throw new ExteniumException("Button is not enabled");
            }
        }

        public void RequireDisabled()
        {
            var result = bool.Parse(SafeExec(Path.Eval() + ".disabled"));
            if (!result)
            {
                throw new ExteniumException("Button is enabled");
            }
        }
    }
}